/*
 * @Description:
 * @Autor: duyu
 * @Date: 2020年12月16日 16:02:28
 * @LastEditors: duyu
 * @LastEditTime: 2020年12月16日 17:00:13
 */
const { app, BrowserWindow } = require('electron')
const path = require('path')
const url = require('url')
const isDev = require('electron-is-dev')

let mainWindow

function createWindow() {
    mainWindow = new BrowserWindow({
        width: 960,
        height: 600,
        titleBarStyle: 'hidden',
        frame: false,
    })

    if(isDev)
        mainWindow.loadURL('http://localhost:3000/')
    else
        mainWindow.loadURL(url.format({
            pathname: path.join(__dirname, 'index.html'),
            protocol: 'file:',
            slashes: true
        }))

    //mainWindow.webContents.openDevTools()
    mainWindow.on('closed', function () {
        mainWindow = null
    })
}

app.on('ready', ()=>{
    createWindow();
    const {Menu} = require('electron')
    Menu.setApplicationMenu(null);
})

app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})

app.on('activate', function () {
    if (mainWindow === null) {
        createWindow()
    }
})
